package com.leetcode.周赛.第234场;

import java.util.HashSet;
import java.util.Set;

/**
 * @author: xiaomi
 * @date: 2021/3/28
 * @description: 5713. 字符串中不同整数的数目
 * https://leetcode-cn.com/contest/weekly-contest-234/problems/number-of-different-integers-in-a-string/
 * 还要小心数组越界的问题
 */
public class A_5713_字符串中不同整数的数目 {

    static A_5713_字符串中不同整数的数目 action = new A_5713_字符串中不同整数的数目();

    public static void main(String[] args) {
        test1();
    }

    static void test1() {
        String word = "a123bc34d8ef34";
        int res = action.numDifferentIntegers(word);
        System.out.println(res);
    }

    public int numDifferentIntegers(String word) {
        char[] chars = word.toCharArray();
        int len = chars.length;
        for (int i = 0; i < len; i++) {
            if (!Character.isDigit(chars[i])) {
                chars[i] = ' ';
            }
        }
        String temp = new String(chars);
        String[] split = temp.split("\\s");
        Set<String> set = new HashSet<>();
        for (String item :
                split) {
            if (!item.isEmpty()) {
                if (item.startsWith("0")) {
                    item = item.replaceAll("^0+", "");
                }
                set.add(item);
            }
        }
        return set.size();
    }


}
